// 打开数据库
var db;

function openDB() {
	/*
	plus.sqlite.openDatabase({
		name: 'first',
		path: '_doc/test.db',
		success: function(e){
			console.log('openDatabase success!');
		},
		fail: function(e){
			console.log('openDatabase failed: '+JSON.stringify(e));
		}
	});*/
	db = openDatabase('myTel', '1.0', 'test db', 1024 * 100); //数据库名 版本 数据库描述 大小
}


// 关闭数据库
function closeDB() {
	/*
	plus.sqlite.closeDatabase({
		name: 'first',
		success: function(e){
			console.log('closeDatabase success!');
		},
		fail: function(e){
			console.log('closeDatabase failed: '+JSON.stringify(e));
		}
	});
	*/
}

// 执行SQL语句
function executeSQL() {
	db.transaction(function(tx) {
			tx.executeSql({
				sql: 'create table if not exists database("where" CHAR(110),"location" CHAR(100),"age" INT(11))',
				success: function(e) {
					console.log('executeSql success!');
					tx.executeSql({
						sql: "insert into database values('北京','安乐林','11')",
						success: function(e) {
							console.log('executeSql success!');
						},
						fail: function(e) {
							console.log('executeSql failed: ' + JSON.stringify(e));
						}
					});
				},
				fail: function(e) {
					console.log('executeSql failed: ' + JSON.stringify(e));
				}
			});
		});
	}

	// 查询SQL语句
	function selectSQL() {
		db.transaction(function(tx) {
				tx.executeSql({
			sql: 'select * from database',
			success: function(data) {
				console.log('selectSql success: ');
				for (var i in data) {
					console.log(data[i]);
				}
			},
			fail: function(e) {
				console.log('selectSql failed: ' + JSON.stringify(e));
			}
		});
		});
	}

	//判断数据库是否打开
	//Boolean plus.sqlite.isOpenDatabase(options);
	//关闭数据库
	//void plus.sqlite.closeDatabase(options);

	function getNetworkType() {
		//获取网络信息
		uni.getNetworkType({
			success: res => {
				this.netWork = res.networkType;
				this.isOpenDB();
			}
		})
	}

	function isOpenDB() {
		this.openDB(); //打開DB  
	}
